#ifndef QuestionItem_H
#define QuestionItem_H

#include "ModelItems\TreeItem.h"
#include "..\..\core\src\AssetManager.h"
#include "..\..\core\src\container\ResponseAttribute.h"

namespace Xps
{
	class QuestionItem : public TreeItem
	{
	public:
		QuestionItem(XpsAssets::AssetManager* am, int id, int pid = -1) : TreeItem(am,id,ModelItemType::QUESTION, pid)
		{
			asset = am->getQuestion(id);
			setIcon(QIcon(":/rs/images/question.png"));
		}

		QVariant QuestionItem::data (int role) const
		{
			XpsAssets::Question* q;
			q = (XpsAssets::Question*) asset;
			
			if (role == Qt::EditRole || role == Qt::DisplayRole)
			{
				return QString("%1 %2").arg(q->id(),3,10,QChar('0')).arg(q->text());
			}

			if (role == Qt::DecorationRole && asset != NULL)
			{
				if (q->choiceMode() == 0)
					return QIcon(":/rs/images/question_oc.png");
				if (q->choiceMode() == 1)
					return QIcon(":/rs/images/question_mc.png");
			}
				
			return TreeItem::data(role);
		}
		
		void QuestionItem::setData ( const QVariant & value, int role)
		{
			if (role != Qt::EditRole) 
				return TreeItem::setData(value,role);

			XpsAssets::Question* q = (XpsAssets::Question*) asset;
			q->setText(value.toString());
		}
	};
}
#endif